package com.jiayang.hhotel.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.SpecialRoomStateModel;
import com.jiayang.hhotel.util.LogUtil;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuAdapter;

import java.util.List;

/**
 * Created by Administrator on 2017/5/16 0016.
 * 特殊房态列表适配器
 */

public class SpecialRoomStateListAdapter extends SwipeMenuAdapter<SpecialRoomStateListAdapter.ViewHolder> {

//    private static final int TYPE_ITEM =0; //普通Item View
//    private static final int TYPE_FOOTER = 1; // 底部FootView

    private Context t;
    private List<SpecialRoomStateModel.PAssignRoomListDtosBean> mList;
    private btClickListener listener;

    public SpecialRoomStateListAdapter(Context context, List<SpecialRoomStateModel.PAssignRoomListDtosBean> list, int page,btClickListener listener){
        LogUtil.showLog("page= "+page);
        if(page == 1){
            this.mList = list;
        }else{
            this.mList.addAll(list);
        }
        this.t = context;
        this.listener = listener;
        LogUtil.showLog("list = "+mList.toString());
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        SpecialRoomStateModel.PAssignRoomListDtosBean model = mList.get(position);
        holder.roomNum.setText(t.getString(R.string.room_num)+t.getString(R.string.space)+model.getRoom());
        holder.state.setText(t.getString(R.string.state)+t.getString(R.string.space) + (model.getAuthorize().equals("0")?"未通过":"通过"));
        holder.type.setText(t.getString(R.string.type)+t.getString(R.string.space)+model.getStatusdescp());
        holder.date.setText(t.getString(R.string.start_stop_date)+t.getString(R.string.space) + model.getBeginDate()+ t.getString(R.string.zhi) + model.getEndDate());
        holder.cause.setText(t.getString(R.string.cause)+t.getString(R.string.space)+model.getSerial());//此处获取数据错误
        holder.bind(model,position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return LayoutInflater.from(t).inflate(R.layout.special_room_state_list_item, parent, false);
    }

    @Override
    public ViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        return new ViewHolder(realContentView);
    }

    class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        TextView roomNum;//房号
        TextView state;//状态
        TextView type;//类型
        TextView date;//起止时间
        TextView cause;//原因

        Button cancel;//取消
        Button end;//结束

        public ViewHolder(View convertView) {
            super(convertView);
            roomNum = (TextView) convertView.findViewById(R.id.tv_room_num);
            state = (TextView) convertView.findViewById(R.id.tv_state);
            type = (TextView) convertView.findViewById(R.id.tv_type);
            date = (TextView) convertView.findViewById(R.id.tv_time);
            cause = (TextView) convertView.findViewById(R.id.tv_cause);

            cancel = (Button) convertView.findViewById(R.id.bt_cancel);
            end = (Button) convertView.findViewById(R.id.bt_end);
        }

        int position;
        void bind(SpecialRoomStateModel.PAssignRoomListDtosBean model,int pos){
            position = pos;
            cancel.setTag(model);
            end.setTag(model);

            cancel.setOnClickListener(this);
            end.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.bt_cancel://取消
                    if(listener!=null){
                        listener.onBTClickListener((SpecialRoomStateModel.PAssignRoomListDtosBean) cancel.getTag(),R.id.bt_cancel,position);
                    }
                    break;
                case R.id.bt_end://结束
                    if(listener!=null){
                        listener.onBTClickListener((SpecialRoomStateModel.PAssignRoomListDtosBean) end.getTag(),R.id.bt_end,position);
                    }
                    break;
            }
        }
    }
    public interface btClickListener{
        void onBTClickListener(SpecialRoomStateModel.PAssignRoomListDtosBean model, int id, int position);
    }
}
